package com.diankangwo.controller;

import com.diankangwo.dto.RefundCheckAccountDTO;
import com.diankangwo.service.RefundCheckAccountService;
import com.diankangwo.util.QueryCAUtil;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.List;

/**
 * 
 * 退费对账
 *
 */
@Controller
@RequestMapping("refundCheckAccount")
public class RefundCheckAccountController {

	@Autowired
	private RefundCheckAccountService refundCheckAccountService;
	
	@RequestMapping
	public String synchronousDate(RedirectAttributes ra) throws UnsupportedEncodingException{
		boolean sysnchronousStatus = refundCheckAccountService.synchronousDate();
		if (!sysnchronousStatus) {
			ra.addAttribute("message",URLEncoder.encode("对账数据同步失败！", "UTF-8"));
		} else {
			ra.addAttribute("message", URLEncoder.encode("对账数据同步成功！", "UTF-8"));
		}
		
		return "redirect:/b-manage/audit";
	}
	
	@RequestMapping(value="query")
	public String queryCA(@NotEmpty QueryCAUtil qcaUtil,RedirectAttributes ra) throws Exception{
		try {
			List<RefundCheckAccountDTO> rcaList = refundCheckAccountService.queryCA(qcaUtil);
			ra.addFlashAttribute("rcaList", rcaList);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
